package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.order.*;
import com.cskaoyan.mapper.OrdergoodsMapper;
import com.cskaoyan.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Ref;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, String start, String end, Short[] orderStatusArray, Integer userId, Integer orderId, String orderSn) {


        BaseData<MarketOrder> result = orderService.list(baseParam, start, end, orderStatusArray, userId, orderId, orderSn);
        return BaseRespVo.ok(result);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        OrderDetail orderDetail = orderService.detail(id);
        return BaseRespVo.ok(orderDetail);
    }


    @RequestMapping("ship")
    //301为发货状态 在market_order表里order_status
//    public BaseRespVo ship(Integer orderId, String shipChannel, String shipSn)
    public BaseRespVo ship(@RequestBody ShipBO shipBO) {

        orderService.ship(shipBO.getOrderId(), shipBO.getShipChannel(), shipBO.getShipSn());
        return BaseRespVo.ok();
    }

    @RequestMapping("refund")
    //203设置退款代码
//    public BaseRespVo refund(Integer orderId,Integer refundMoney)
    public BaseRespVo refund(@RequestBody RefundBO refundBO) {
        orderService.refund(refundBO.getOrderId(), refundBO.getRefundMoney());
        return BaseRespVo.ok();
    }


    @RequestMapping("channel")
    public BaseRespVo channel() {
        List<Channel> channels = orderService.channel();
        return BaseRespVo.ok(channels);
    }

    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody CommentBO commentBO) {
        int reply = orderService.reply(commentBO.getCommentId(), commentBO.getContent());
        if (reply == 0) {
            return BaseRespVo.fail("无法重复评论");
        }
        return BaseRespVo.ok();
    }



}
